﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Text;
using Rison.Web.Common;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.XT;
using Rison.BusinessFacade.Facade.XT;
using Rison.BusinessFacade.Helper;

namespace Rison.Web.admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
                CurrentLoginedUser.ClearUserSession();
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (StringHelper.IsNullOrEmpty(this.txtUserId.Text))
                this.labMsg.Text = "请输入用户名！";
            else if (!StringHelper.IsMergeByNumberAndChar(txtUserId.Text.Trim(), "_"))
                this.labMsg.Text = "用户名输入非法！";
            else if (StringHelper.IsNullOrEmpty(this.txtPwd.Text))
                this.labMsg.Text = "请输入密码！";
            else
            {
                CurrentLoginedUser.SetCurrentUserId(txtUserId.Text.Trim(), this.txtPwd.Text);

                if (string.IsNullOrEmpty(CurrentLoginedUser.UserId))
                    this.labMsg.Text = "对不起，用户名或密码错误！";
                else if (!txtPwd.Text.Equals(CurrentLoginedUser.Password))
                    this.labMsg.Text = "对不起，密码错误！";//区分大小写
                else
                    Response.Redirect("AdminView.aspx");
            }
        }
    }
}
